package concurrent.chapter2;

public class WaitSet2 {
    private static final Object LOCK = new Object();

    private static void work() {
        synchronized (LOCK) {
            System.out.println("Begin...");
            try {
                System.out.println("Thread will coming");
                LOCK.wait(); //4.线程被唤醒后，必须重新获取锁，从这里开始执行后续代码
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread will out.");

        }
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread() {
            @Override
            public void run() {
                work();
            }
        }.start();
        Thread.sleep(1000);
        synchronized (LOCK) {
            LOCK.notify();
        }
    }
}
